package org.oschina.api.upload.controller;

import org.oschina.api.BaseController;
import org.oschina.api.upload.service.UploadService;
import org.oschina.bean.Result;
import org.oschina.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(value=Config.API_PATH+"/upload")
public class UploadController extends BaseController {

	@Autowired
	private UploadService uploadService;
	
	/**
	 * 普通上传
	 * @param file
	 * @return
	 */
	@RequestMapping(value="/simple",method=RequestMethod.POST)
	public Result simple(MultipartFile file)
	{
		return uploadService.simple(toFile(file));
	}
	
	/**
	 * 上传用户头像
	 * @param file
	 * @return
	 */
	@RequestMapping(value="/user/headphoto",method=RequestMethod.POST)
	public Result user_headphoto(MultipartFile file)
	{
		return uploadService.user_headphoto(toFile(file));
	}
	
	/**
	 * 上传软件图标
	 * @param file
	 * @return
	 */
	@RequestMapping(value="/software/icon",method=RequestMethod.POST)
	public Result software_icon(MultipartFile file)
	{
		return uploadService.software_icon(toFile(file));
	}
}